package observer_pattern.v1;

import java.util.ArrayList;
import java.util.List;

/**
 * 前台秘书类
 * @author ricejson
 */
public class Secretary {
    private String name;
    private List<StockObserver> observerList = new ArrayList<>();
    private String action;

    public Secretary(String name) {
        this.name = name;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getAction() {
        return action;
    }

    public void attach(StockObserver observer) {
        observerList.add(observer);
    }

    public void detach(StockObserver observer) {
        observerList.remove(observer);
    }

    public void broadcast() {
        for (StockObserver observer : observerList) {
            observer.update();
        }
    }
}
